package com.example.music_project.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.music_project.R;
import com.example.music_project.entity.Music;

import java.util.List;

public class MusicAdapter extends ArrayAdapter<Music> {

    private int resourceId;

    public MusicAdapter(@NonNull Context context, int resource, @NonNull List<Music> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Music music = getItem(position);
        View musicView = LayoutInflater.from(getContext()).inflate(resourceId,null);
        TextView nameText = musicView.findViewById(R.id.text_music);
        ImageView img = musicView.findViewById(R.id.image_music);
        TextView authorText = musicView.findViewById(R.id.text_author);
        nameText.setText(music.getName());
        img.setImageResource(music.getImg());
        authorText.setText(music.getAuthor());
        return musicView;
    }




}
